package com.hatch.utils
{
	public class Validation
	{
		public function Validation()
		{
		}
		/**
		 *	Returns boolean based on validity of name string provided.
		 *
		 *	@param nameStr The string.
		 *
		 *	@param exceptions An array of strings that the name must equal to qualify
		 *
		 *	@returns Boolean
		 *
		 * 	@langversion ActionScript 3.0
		 *	@playerversion Flash 9.0
		 */
		public static function validateName(nameStr:String, exceptions:Array = null):Boolean
		{
			//return if length less than quilified amount
			if(nameStr.length < 2) return false;
			
			if(exceptions)
			{
				//loop through provided exceptions and check for similarities
				for each(var exception:String in exceptions)
					if(nameStr == exception) return false;
			}
			return true;
		}
						/**
		 *	Returns boolean based on validity of email string provided
		 *
		 *	@param emailStr The email string.
		 *
		 *	@param exceptions An array of strings that the name must equal to qualify.
		 *
		 *	@returns Boolean
		 *
		 * 	@langversion ActionScript 3.0
		 *	@playerversion Flash 9.0
		 */
		public static function validateEmail(emailStr:String, exceptions:Array = null):Boolean
		{
			//check to see if there are at least two chars be for the @ symbol
			if (emailStr.indexOf("@") < 1) return false;

			//check that the @ is not within 2 chars of .
			if (emailStr.lastIndexOf(".") <= (emailStr.lastIndexOf("@") + 1)) return false;

			//check length eg min aa@bb.cc
			if (emailStr.length < 6) return false;

			//check there is only one @
			if (emailStr.indexOf("@") != emailStr.lastIndexOf("@")) return false;
			
			if(exceptions)
			{
				//loop through provided exceptions and check for similarities
				for each(var exception:String in exceptions)
					if(emailStr == exception) return false;
			}

			return true;
		}
	}
}